#include <iostream>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
using namespace std;
bool cmp(const pair<int, int>&a, const pair<int, int>&b)
{
	return a.second < b.second;
}
int main()
{
	int t; cin >> t;
	while (t--)
	{
		map<int, int>a;
		int n; cin >> n;
		while (n--)
		{
			int temp;
			cin >> temp;
			a[temp]++;
		}
		map<int, int>::iterator max = max_element(a.begin(), a.end(), cmp);
		cout << max->first << ' ' << max->second << endl;
	}
	return 0;
}